package com.ai.rag;

import jakarta.annotation.Resource;
import org.springframework.ai.document.Document;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.vectorstore.SimpleVectorStore;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.List;

/**
 *恋爱大师向量数据库配置 （初始化基于内存的向量数据库Bean）
 */
@Configuration
public class LoveAppVectorStoreConfig {

    @Resource
    private LoveAppDocumentLoader loveAppDocumentLoader;

    @Resource
    private MyTokenTextSplitter tokenTextSplitter;
    @Resource
    private  MyKeywordEnricher myKeywordEnricher;

    @Bean
    VectorStore loveAppVectorStore(EmbeddingModel dashscopeEmbeddingModel) {
        SimpleVectorStore  builder = SimpleVectorStore.builder(dashscopeEmbeddingModel).build();
        //加载文档
        List<Document> documents = loveAppDocumentLoader.loadMarkdowns();
        // 加载文档后进行切词,自主切分
//        List<Document> splitDocuments = tokenTextSplitter.splitDocuments(documents);
        // 自动补充关键词信息
        List<Document> enrichKeyword = myKeywordEnricher.enrichKeyword(documents);
        builder.add(enrichKeyword);
        return builder;
    }
}
